﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DONGACS.Assembler;
using DONGACS.DAO;
using DONGACS.Domain;
using DONGACS.DTO;
using System.Transactions;


namespace DONGACS.SERVICE
{
    public class PermissionsPublicService
    {
        PermissionsPublicAssembler PermissionsPublicAssembler = new PermissionsPublicAssembler();
        PermissionsPublicDao PermissionsPublicDao = new PermissionsPublicDao();


        public IList<PermissionsPublicDto> GetAllPermissionsPublic()
        {
            IList<PermissionsPublic> permissionsAllUsersList = PermissionsPublicDao.GetAllPermissionsPublic();

            IList<PermissionsPublicDto> permissionsAllUsersDtoList = PermissionsPublicAssembler.ConvertToDataTransferObjectList(permissionsAllUsersList);

            return permissionsAllUsersDtoList;
        }

        // 
        public bool DeleteAllPermissionsPublic()
        {
           return PermissionsPublicDao.DeleteAllPermissionsPublic();
        }

        public bool DeleteAllPermissionAllUsersByListPathsId(IList<int> listPathID)
        {
            return PermissionsPublicDao.DeleteAllPermissionPublicByListPathsId(listPathID);
        }

        public bool AddNewPermissionsPublic(PermissionsPublicDto permissionsAllUsersDto)
        {
            return  PermissionsPublicDao.AddNewPermissionsPublic(PermissionsPublicAssembler.ConvertToBusinessObject(permissionsAllUsersDto));
        }

        //[Transaction] : Cần thiết
        public void UpdatePermissionsPublic(IList<PermissionsPublicDto> PermissionsPublicDtos)
        {
            ////delete all permission for all user
            this.PermissionsPublicDao.DeleteAllPermissionsPublic();

            ////update new setting
            foreach (var dto in PermissionsPublicDtos)
            {
                this.PermissionsPublicDao.AddNewPermissionsPublic(
                    this.PermissionsPublicAssembler.ConvertToBusinessObject(dto));
            }
        }

    }
}
